package zero.tech.wsnet.node;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class NodeCacheClient {
	public static final Map<String, NodeClient> clients = new ConcurrentHashMap<String, NodeClient>();

	public static void add(NodeClient wsClient) {
		String playerId = wsClient.getPlayerId();
		NodeClient oldClient = clients.get(playerId);
		if (oldClient != null) {
			oldClient.activeClose();
		}
		clients.put(playerId, wsClient);
	}

	public static void remove(NodeClient webClient) {
		NodeClient now = clients.get(webClient.getPlayerId());
		if (now != null && now.equals(webClient)) {
			clients.remove(webClient.getPlayerId());
		}
	}
}
